package main

import (
	"time"
)

func main() {
	ch1 := make(chan int)
	ch2 := make(chan int)
	ch3 := make(chan int)
	ch4 := make(chan int)

	go func() { ch1 <- 1 }()
	go PrintNum(ch1, ch2, 1)
	go PrintNum(ch2, ch3, 2)
	go PrintNum(ch3, ch4, 3)
	go PrintNum(ch4, ch1, 4)

	time.Sleep(time.Second * 10)
}

func PrintNum(ch, nextCh chan int, num int) {
	for {
		time.Sleep(time.Second * 1)
		<-ch
		if num == 4 {
			println(num)
		} else {
			print(num)
		}
		nextCh <- 1
	}
}
